using System;
using System.Collections.Generic;
using System.Text;
using java.util.concurrent;
using org.apache.mina.common;
using java.net;

namespace PDSClient.Utils.IO.Impl
{
    public class AbstractSocketEndpoint
    {
        protected SocketAddress address;

        protected TransportType transportType;

        protected Executor executor;

        protected int numProcessors;

        private static Executor defaultExecutor =
            Executors.newCachedThreadPool(new DaemonThreadFactory());

        static AbstractSocketEndpoint()
        {
            ByteBuffer.setAllocator(new SimpleByteBufferAllocator());

            ByteBuffer.setUseDirectBuffers(false);
        }

        protected AbstractSocketEndpoint(SocketAddress address, TransportType type) : this(address, type, defaultExecutor, 1)
        {
        }

        protected AbstractSocketEndpoint(SocketAddress address,
        TransportType type, Executor executor, int numProcessors)
        {
            if (address == null || executor == null) // || type == null
            {
                throw new ArgumentException("null arg");
            }
            if (numProcessors <= 0)
            {
                throw new ArgumentException("numProcessors must be >= 1");
            }
            this.address = address;
            this.transportType = type;
            this.executor = executor;
            this.numProcessors = numProcessors;
        }

        public SocketAddress Address { get { return address; } }

        public TransportType TransportType { get { return transportType; } }

        public Executor Executor { get { return executor; } }

        public int NumProcessors { get { return numProcessors; } }

        public override string ToString()
        {
            return GetType().Name + "[" + Address + "]";
        }

    }
}
